package cn.xorange.commons.system.entity.common;

import cn.xorange.commons.data.annotation.MColumn;
import cn.xorange.commons.data.core.entity.BaseEntity;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

/**
 * @author : yangjian
 * date : 2023/11/4
 * description :
 */
@Data
public class SysArea extends BaseEntity {
    @MColumn
    private String id;
    @MColumn
    private String parentId;
    @MColumn
    @JsonIgnore
    private Integer level;
    @MColumn
    private String name;
    @MColumn(col = "full_name")
    private String fullname;

    private JSONObject location;
    @MColumn
    private Float lat;
    @MColumn
    private Float lng;
    @MColumn
    private String pinyin;

    private static String[] zxs ={"110000","120000","310000","500000","810000","820000"};


    //public void setId(String id){
    //    this.id= id;
    //    this.level = 2;
    //    if(this.level==0){
    //        this.parentId ="0";
    //    }else if(this.level==1){
    //        String sb = id.substring(0,2);
    //        this.parentId = sb+"0000";
    //        for(String s:zxs){
    //            if(id.equals(s)){
    //                this.level =2;
    //            }
    //        }
    //    }else if(this.level==2){
    //        String sb = id.substring(0,4);
    //        this.parentId = sb+"00";
    //    }
    //
    //
    //}

    //public void setFullname(String fullname){
    //    this.fullName = fullname;
    //    this.level = 0;
    //}

    public void setPinyin(JSONArray pinyin){
        if(!pinyin.isEmpty()){
            StringBuilder sb = new StringBuilder();
            for (Object o : pinyin) {
                sb.append(o);
                sb.append(" ");
            }
            sb.deleteCharAt(sb.length()-1);
            this.pinyin = sb.toString();
        }
    }
    public void setPinyin(String py){
        this.pinyin = py;
    }

    public void setLocation(JSONObject location){
        this.location = location;
        if(!this.location.isEmpty()){
            this.lat = this.location.getFloat("lat");
            this.lng = this.location.getFloat("lng");
        }
    }




}
